Skip to content

Fix Pages and Workers static asset uploads in Code Mode - #439

Draft
irvinebroque wants to merge 2 commits into
cloudflare:mainfrom
irvinebroque:codex/static-asset-upload-auth
Draft

irvinebroque wants to merge 2 commits into
cloudflare:mainfrom
irvinebroque:codex/static-asset-upload-auth

Conversation

@irvinebroque

Copy link
Copy Markdown

Pages Direct Upload and Workers static asset uploads can mint an upload JWT in Code Mode, but the upload fails even when the caller sends the right token. GlobalOutbound replaces it with the MCP connection token. Fixing credential selection at that shared boundary covers both cloudflare.request() and native fetch() without changing either caller API.

flowchart TD
  subgraph before[Before]
    direction LR
    B1["Mint upload JWT with MCP token"] --> B2["Caller sends upload JWT"]
    B2 --> B3["Proxy replaces it with MCP token"]
    B3 --> B4["Upload API rejects the request"]
  end
  subgraph after[After]
    direction LR
    A1["Mint upload JWT with MCP token"] --> A2["Caller sends upload JWT"]
    A2 --> A3["Proxy sends only the upload JWT"]
    A3 --> A4["Upload succeeds; finalize with MCP token"]
  end
Loading

Same caller code (Workers multipart upload):

await cloudflare.request({
  method: 'POST',
  path: `/accounts/${accountId}/workers/assets/upload`,
  query: { base64: true },
  headers: { Authorization: `Bearer ${uploadJwt}` },
  body: assetForm
})

What changes on the wire:

 POST /client/v4/accounts/{account_id}/workers/assets/upload?base64=true
-Authorization: Bearer <MCP connection token>
+Authorization: Bearer <upload JWT>

The proxy checks the configured API origin and base path first. Only the three Pages asset POSTs (check-missing, upload, upsert-hashes) and the Workers asset upload POST can use the upload JWT. If it is missing, malformed, or stale beyond the clock-skew allowance, the proxy stops before sending the request. The upload API still verifies the JWT signature and scope. Uploads aren’t redirected or replayed after a transport failure, and upload-token denials don’t trigger an MCP OAuth scope prompt. Everything else, including minting the JWT and finalizing the deployment, still uses the MCP connection token.

Builds on #429 by @acoyfellow; the draft retains the original contribution and adds the fail-closed credential handling on top.

Fixes #386. Fixes #389.

acoyfellow and others added 2 commits November 24, 2026 08:20
Pages Direct Upload and Workers static assets need a short-lived JWT as the
bearer on the asset endpoints. execute always sent the session's token, so
every upload failed with 403 (8000013).

Forward the code's bearer only on the four asset upload POSTs, and only when it
is an unexpired JWT other than the session token.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants